package com.whut.common;

import com.whut.common.util.ExecuteTemp;
import lombok.Data;

import java.io.Serializable;

@Data
public class BaseRes<T> implements Serializable {
    private static final long serialVersionUID = 4308086017390700920L;
    private T data;
    private String message = "ok";
    private boolean success = true;
    private Long timestamp;
    private Integer version;

    public BaseRes() {
    }

    public BaseRes(T data) {
        this.data = data;
    }

    public static <T> BaseRes<T> success(T data) {
        return new BaseRes<>(data);
    }

    public static <T> BaseRes<T> getTemp(ExecuteTemp<T> temp) {
        BaseRes<T> res = new BaseRes<>();
        try {
            res.setData(temp.execute());
        } catch (Throwable e) {
            e.printStackTrace();
            res.setSuccess(false);
            res.setMessage(e.getMessage());
        }
        return res;
    }
}
